package com.woniu.controller;

import com.woniu.entity.PageData;
import com.woniu.entity.Result;
import com.woniu.entity.dto.QueryUserFeedBackDTO;
import com.woniu.pojo.User;
import com.woniu.pojo.UserFeedback;
import com.woniu.service.UserFeedbackService;
import com.woniu.utils.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "用户反馈表管理")
@RestController
@RequestMapping("/userfeedback")
@CrossOrigin
public class UserFeedBackController extends BaseController {

    @Autowired
    private UserFeedbackService userFeedbackService;

    @ApiOperation("搜索+分页")
    @PostMapping("/list/search/{currentPage}/{pageSize}")
    public Result listSearch(
            @PathVariable Integer currentPage,
            @PathVariable Integer pageSize,
            @RequestBody(required = false) QueryUserFeedBackDTO queryUserFeedBackDTO){
        PageData pageData =  userFeedbackService.listSearch(currentPage, pageSize, queryUserFeedBackDTO);
        return toDataResult(pageData);
    }

    @ApiOperation("新增或者修改")
    @PostMapping
    public Result saveOrUpdate(@RequestBody UserFeedback userFeedback){
        boolean flag = userFeedbackService.saveOrUpdate(userFeedback);
        return toResult(flag);
    }

    @ApiOperation("删除操作")
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable String id){
        boolean flag = userFeedbackService.removeById(id);
        return toResult(flag);
    }

    @ApiOperation("根据ID查询")
    @GetMapping("/{id}")
    public Result getById(@PathVariable String id){
        UserFeedback userFeedback = userFeedbackService.getById(id);
        return toDataResult(userFeedback);
    }


    @ApiOperation("根据ID查询用户信息")
    @GetMapping("/user/{id}")
    public Result getByUser(@PathVariable String id){
        User user = userFeedbackService.getByUser(id);
        return toDataResult(user);
    }

}
